Skip to main content

English

Install Julia packages

Requirements to install packages

Requirements to install packages networked (must have Internet access)

  • Connect to login0 of MareNostrum4:

    mylaptop$> ssh {username}@mn0.bsc.es
    IMPORTANT

    The MareNostrum4 login0 is restricted to BSC staff and is only accessible from the BSC internal network or the Virtual Private Network (VPN).

  • Check the Internet connectivity from login0, for example:

    $> wget --tries=3 --timeout=5 -q --spider google.com && echo "Networked" || echo "Non-networked"
    Networked

Check the 'Pkg' package manager

Pkg is Julia's built-in package manager that handles operations like installing, updating and removing packages.

  • Load Julia in the session, for example:

    $> module load julia/1.4.2
  • Ensure you can run Julia from the command line:

    $> which julia
    /apps/JULIA/1.4.2/bin/julia
    $> julia --version
    julia version 1.4.2
  • Access the interactive command-line REPL (read-eval-print loop) with all built-in functions:

    1. Open a Julia terminal, by executing the command "julia"
    2. Type "]"
  • Show REPL help:

    (v1.4) pkg> help

    Or:

    (v1.4) pkg> ?

Install and manage packages

Install packages

  • Install a package (along with all its dependencies):

    (v1.4) pkg> add SomePackage         # Latest version
    (v1.4) pkg> add SomePackage@0.4 # Specific version
    (v1.4) pkg> add SomePackage#master # Unregistered version
  • Install multiple packages at once:

    (v1.4) pkg> add A B C D
  • Install a package by specifying the URL or local path to a git repository:

    (v1.4) pkg> add https://github.com/SomeProject/SomeProject.jl

Update/rebuild/prebuild packages

  • Update one or more packages:

    (v1.4) pkg> update SomePackage
    (v1.4) pkg> up SomePackage
    (v1.4) pkg> up A B C D
    (v1.4) pkg> update # All packages
  • Rebuild a specific package (along with all its dependencies recursively):

    (v1.4) pkg> build SomePackage
    REMARK

    Note that the build step is automatically run when a package is first installed.

  • Precompile a project (maybe you also want to pre-update all project dependencies):

    (julia) pkg> update; precompile
  • "Pin" a package:

    (v1.4) pkg> pin SomePackage
    REMARK

    A pinned package will never be updated, showing up on the stack with a 'pin' symbol.

  • "Unpin" a package:

    (v1.4) pkg> free SomePackage

Uninstall packages

  • Uninstall one or more packages:

    (v1.4) pkg> remove SomePackage
    (v1.4) pkg> rm SomePackage
    (v1.4) pkg> rm A B C D
  • Uninstall a package that only exists as a dependency:

    (v1.4) pkg> rm --manifest SomePackage
    caution

    This action will also remove all dependencies of the package in question.

Undo/redo changes during a session

  • Undo the last change in the current project:

    (julia) pkg> undo
    caution

    Only the states of the current session are stored, up to a maximum of 50 states.

  • Undo the last changes since the last undo operation we did:

    (julia) pkg> redo

Work with environments

By default, Julia sets '~/.julia' as the base directory of the initial active project, where it will place the project's packages and configuration files.

  • Change default location of the initial active project:

    $> export JULIA_PROJECT=/path/to/some/julia/project
    $> julia

    Or:

    $> julia --project=/path/to/some/julia/project

It is easy to work with independent projects in Julia by using environments. On the other hand, when two projects use the same package in the same version, the content of this package is not duplicated.

  • Show active environment information:

    (v1.4) pkg> st [ --project ]    # Show packages added by yourself
    (v1.4) pkg> st --manifest # Show all packages in the environment, including recursive dependencies
  • Create a new environment or switch to an existing one:

    (v1.4) pkg> activate /path/to/NewProject
    Activating new environment at `/path/to/NewProject/Project.toml`

    (v1.4) pkg> activate /path/to/ExistingProject
    Activating environment at `/path/to/ExistingProject/Project.toml`
  • Another kind of thing that you can do "hot" is the following:

    julia> mkdir("MyProject")       # In 'julia' mode

    julia> cd("MyProject") # In 'julia' mode

    (v1.4) pkg> activate . # In 'pkg' mode

    (MyProject) pkg> st # Note that the REPL prompt changed
    Status `Project.toml` # As this is a newly created project,
    # the 'status' command shows that it contains no packages
  • Return to the default environment:

    (SomeProject) pkg> activate
    Activating environment at `~/.julia/environments/v1.4/Project.toml`

    (v1.4) pkg>